<template>
  <div>
    <!-- 轮播图 -->
    <div class="block text-center" m="t-4">
      <el-carousel trigger="click" height="320px" width="690px">
        <el-carousel-item v-for="item in carouselItems" :key="item.id">
          <h3 class="small justify-center" text="2xl">{{ item.alt }}</h3>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div style="box-shadow: var(--el-border-color-light) 0px 0px 10px">
      <el-splitter>
        <el-splitter-panel size="70%" :resizable="false">
          <div class="main-panel">
            <!-- 模拟文章 -->
            <div class="demonstrations">
              <div class="article-container">
                <div
                  class="article-card"
                  v-for="(item, index) in articles"
                  :key="index"
                >
                  <div class="card-header">
                    <h3 class="article-title">{{ item.title }}</h3>
                    <div class="article-meta">
                    </div>
                  </div>

                  <div class="card-body">
                    <p class="article-excerpt">{{ item.summary  }}</p>
                    <el-image
                      class="article-image"
                      :src="item.cover"
                      alt="文章图片"
                    >
                    <template #error>
                      <div class="image-slot">
                        <p>图片加载失败</p>
                      </div>
                    </template>
                  </el-image>
                  </div>

                  <div class="card-footer">
                    <div class="article-tags">
                      <span
                        class="tag"
                        v-for="(tag, tagIndex) in item.tags"
                        :key="tagIndex"
                      >
                        {{ tag }}
                      </span>
                    </div>

                    <div class="article-stats">
                      <!-- 浏览量 -->
                      <div class="stat-item">
                        <el-icon>
                          <View />
                        </el-icon>
                        <span>{{ formatNumber(item.views) }}</span>
                      </div>
                      
                      <!-- 点赞量 -->
                      <div class="stat-item " :class="{ liked: item.isLiked }" @click="toggleLike(item)">
                         <el-icon>
                          <Star/>
                        </el-icon>
                        <span>{{ formatNumber(item.likes) }}</span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-splitter-panel>
        <el-splitter-panel :min="200">
          <div class="main-panel">
            <!-- 热点搜索排行 -->
            <div class="hot-search-container">
              <div class="hot-search-title">
                <i class="fas fa-fire"></i>
                <h2>热搜排行榜</h2>
              </div>
              <ul class="hot-search">
                <li v-for="(hot, index) in hotSearchList" :key="index">
                  <div class="rank">{{ index + 1 }}</div>
                  <div class="text">{{ hot.text }}</div>
                  <div class="hot-indicator">
                    <i class="fas fa-fire"></i>
                    <span>{{ hot.hotValue }}</span>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </el-splitter-panel>
      </el-splitter>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { Search, View, StarFilled, Star, CloseBold, UserFilled } from "@element-plus/icons-vue";
import { useHead } from "nuxt/app";
import { it } from "element-plus/es/locales.mjs";

// 设置页面标题
useHead({
  title: "首页 - 水晶战争游戏平台",
});

const search = ref("");
function onSearch() {
  // 实时搜索逻辑，可以根据 search 的值进行过滤
  console.log("搜索内容:", search.value);
}

// 热搜数据
const hotSearchList = ref([
  { text: "新英雄技能解析", hotValue: "982万" },
  { text: "赛季奖励皮肤预览", hotValue: "756万" },
  { text: "竞技模式地图调整", hotValue: "643万" },
  { text: "玩家创作大赛", hotValue: "521万" },
  { text: "职业联赛赛程", hotValue: "487万" },
  { text: "版本更新公告", hotValue: "432万" },
  { text: "游戏优化计划", hotValue: "398万" },
  { text: "新手入门指南", hotValue: "365万" },
  { text: "社区活动预告", hotValue: "342万" },
]);

// 文章数据
const articles = ref([
  {
    title: "新版本角色平衡性调整详解",
    summary :
      "本次更新对多个英雄进行了平衡性调整，旨在提升游戏体验和竞技公平性。以下是详细调整内容...",
    cover:
      "https://bbs-static.miyoushe.com/static/2025/08/20/d5e106223a1fb4f664b6bdc1215191a9_5427551948519960559.jpg",
    user: {
      name: "官方策划",
      avatar:
        "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
    },
    createTime: new Date(2023, 7, 20),
    tags: ["更新", "平衡性", "攻略"],
    views: 1245,
    likes: 324,
    isLiked: false,
  },
  {
    title: "水晶战争竞技模式进阶指南",
    summary :
      "想要在竞技模式中提升段位？这篇指南将为你详细介绍高阶战术和团队配合技巧...",
    cover:
      "https://bbs-static.miyoushe.com/static/2025/08/18/4b1e1b3b7a8c4e6f9a2b5c8d0e1f3a4_1234567890123456789.jpg",
    user: {
      name: "职业选手",
      avatar:
        "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
    },
    createTime: new Date(2023, 7, 18),
    tags: ["攻略", "竞技", "技巧"],
    views: 2876,
    likes: 512,
    isLiked: false,
  },
  {
    title: "游戏背景故事：水晶的起源",
    summary :
      "探索水晶战争的世界观和背景故事，了解这个充满魔法与科技的世界是如何形成的...",
    cover:
      "https://bbs-static.miyoushe.com/static/2025/08/15/7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2_9876543210987654321.jpg",
    user: {
      name: "剧情设计师",
      avatar:
        "https://cube.elemecdn.com/9/c2/f0eea6c22c34fc3f36c9f90c5c17epng.png",
    },
    createTime: new Date(2023, 7, 15),
    tags: ["剧情", "世界观", "背景故事"],
    views: 3562,
    likes: 687,
    isLiked: false,
  },
  {
    title: "社区创作大赛结果公布",
    summary :
      "感谢各位玩家的积极参与！以下是本次社区创作大赛的获奖作品名单及奖励发放说明...",
    cover:
      "https://bbs-static.miyoushe.com/static/2025/08/10/1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6_5678901234567890123.jpg",
    user: {
      name: "社区经理",
      avatar:
        "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48png.png",
    },
    createTime: new Date(2023, 7, 10),
    tags: ["社区", "活动", "比赛"],
    views: 1987,
    likes: 423,
    isLiked: false,
  },
]);

const carouselItems = ref([
  { id: 1, image: "", alt: "Image 1" },
  { id: 2, image: "", alt: "Image 2" },
  { id: 3, image: "", alt: "Image 3" },
]);

// 点赞功能
const toggleLike = (post: any) => {
  post.isLiked = !post.isLiked
  post.likes += post.isLiked ? 1 : -1
}

// 数字格式化方法
function formatNumber(value: number) {
  if (value >= 10000) {
    return (value / 10000).toFixed(1) + '万'
  }
  return value
}
</script>

<style scoped>
.demonstration {
  color: var(--el-text-color-secondary);
}

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.demonstrations {
  margin-top: 20px;
  flex-wrap: wrap;
  gap: 20px;
  width: 1200px;
  justify-content: center;
  display: grid;
}
.el-card {
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.article-image {
  margin-top: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  float: right;
  height: 200px;
  width: auto;
}
.card-body {
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 8px;
  height: 262px;
}
.article-content {
  margin-bottom: 20px;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  max-width: 656px;
}
.main-panel {
  width: 90%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 30px;
  transition: transform 0.3s ease;
}

.main-panel:hover {
  transform: translateY(-5px);
}

.search-bar {
  margin-bottom: 30px;
  position: relative;
}

.search-input-container {
  position: relative;
  display: flex;
  align-items: center;
}

.el-input__inner {
  border: none;
  box-shadow: none;
}

.search-input:focus {
  background: white;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.search-icon {
  position: absolute;
  left: 20px;
  color: #7b8794;
  font-size: 20px;
  z-index: 2;
}

.hot-search-container {
  background: white;
  border-radius: 15px;
  padding: 20px;
}

.hot-search-title {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f0f5f9;
}

.hot-search-title i {
  color: #ff6b6b;
  font-size: 24px;
  margin-right: 10px;
}

.hot-search-title h2 {
  font-size: 22px;
  font-weight: 600;
  color: #2d3436;
}

.hot-search {
  list-style: none;
  /* 左偏移 */
  padding-left: 20px;
}

.hot-search li {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  margin-bottom: 10px;
  border-radius: 12px;
  background: #f8f9fa;
  transition: all 0.3s ease;
  cursor: pointer;
}

.hot-search li:hover {
  background: #edf2ff;
  transform: translateX(5px);
}

.hot-search li .rank {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #dee2e6;
  color: #495057;
  font-weight: 600;
  margin-right: 15px;
  font-size: 14px;
}

.hot-search li:nth-child(1) .rank {
  background: #ff6b6b;
  color: white;
}

.hot-search li:nth-child(2) .rank {
  background: #feca57;
  color: white;
}

.hot-search li:nth-child(3) .rank {
  background: #48dbfb;
  color: white;
}

.hot-search li .text {
  flex: 1;
  font-size: 16px;
  color: #2d3436;
}

.hot-search li .hot-indicator {
  display: flex;
  align-items: center;
  color: #ff6b6b;
  font-size: 14px;
  font-weight: 500;
}

.hot-search li .hot-indicator i {
  margin-right: 5px;
}

@media (max-width: 600px) {
  .main-panel {
    padding: 20px;
  }

  .search-input {
    padding: 15px 20px 15px 45px;
    font-size: 16px;
  }

  .search-icon {
    left: 15px;
    font-size: 18px;
  }

  .hot-search-title h2 {
    font-size: 20px;
  }

  .hot-search li {
    padding: 12px 15px;
  }

  .hot-search li .text {
    font-size: 15px;
  }
}

.article-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.article-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.article-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.card-header {
  padding: 20px 20px 15px;
  border-bottom: 1px solid #f0f0f0;
}

.article-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 12px;
  line-height: 1.4;
}

.article-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 30px;
  
}

.author-info {
  display: flex;
  align-items: center;
}

.author-avatar {
  width: 29px;
  height: 29px;
  display: flex;
  border-radius: 50%;
  margin-right: 8px;
  object-fit: cover;
}

.author-name {
  font-size: 0.9rem;
  color: #666;
}

.publish-date {
  font-size: 0.85rem;
  color: #888;
  display: flex;
  align-items: center;
}

.publish-date i {
  margin-right: 5px;
}

.card-body {
  padding: 15px 20px;
}

.article-excerpt {
  color: #444;
  line-height: 1.6;
  margin-bottom: 15px;
  font-size: 0.95rem;
}

.article-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 8px;
}

.card-footer {
  padding: 15px 20px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #f0f0f0;
}

.article-tags {
  display: flex;
  gap: 8px;
}

.tag {
  background: #f0f5ff;
  color: #1a53ff;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 500;
}

.article-stats {
  display: flex;
  gap: 15px;
}

.stat-item {
  display: flex;
  align-items: center;
  color: #666;
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.2s ease;
}

.stat-item i {
  margin-right: 5px;
}

.stat-item.liked {
  color: #ff3b30;
}

.stat-item:hover {
  color: #1a53ff;
}

.stat-item.liked:hover {
  color: #ff3b30;
}

@media (max-width: 768px) {
  .article-container {
    grid-template-columns: 1fr;
    padding: 15px;
  }

  .article-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .card-footer {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .article-stats {
    width: 100%;
    justify-content: flex-end;
  }
}
.image-slot {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f0f0f0;
  color: #ccc;
}
</style>
